Ticket #2233: correct conversion to Q.txt

File correct conversion to Q.txt, 3.0 KB (added by Nick Draper, 10 years ago)
Line 
1From:   Taylor, Jon (STFC,RAL,ISIS)
2Sent:   12 January 2011 09:37
3To:     Draper, Nick (-,RAL,ISIS)
4Subject:        correct conversion to |Q|
5
6Follow Up Flag: Follow up
7Flag Status:    Flagged
8
9Hi
10I've dug out the matlab routines we use to calculate |Q| as well as Qx,Qy,Qz
11for both direct and indirect geometries
12They are below
13first we calculate Qx,Qy,Qz.
14then calculate modQ
15Thanks
16Jon
17
18function modQ=spe2modQ(data)
19
20Q=spe2sqe(data);
21modQ=sqrt(Q(:,:,1).^2+Q(:,:,2).^2+Q(:,:,3).^2);
22
23function Q=spe2sqe(spe_data)
24
25% function Q=spe2sqe(spe_data)
26% fields required of spe_data: emode, efixed[meV], en(1,ne)[meV],
27det_theta(ndet,1)[rad],
28%                   det_psi(ndet,1)[rad](not necessary for IRIS)
29% returns : Q(ndet,ne,3)[?^{-1}]
30% emode=1 if efixed=ei (HET and MARI) and emode=2 if efixed=ef (IRIS)
31% transforms data points in the form (detector_angles,energy) ->
32(Qx,Qy,Qz,energy)
33% in the spectrometer frame where x=[1 0 0] along +k_i, [0 1 0] in the horiz
34scattering plane
35% and z=[0 0 1] \perp to the horizontal plane
36% 11-sep-98 modify const E=2.07k^2 to compare results with PHOENIX, exact
37match
38% restore E/k^2=2.072
39
40if spe_data.emode==1,
41   
42   % ======================================================================
43        % For direct-geometry spectrometers like HET, MARI
44        % efixed = monochromatic incident energy ei(meV)
45        % ======================================================================
46
47   ki=sqrt(spe_data.efixed/2.07);       % scalar
48        kf=sqrt((spe_data.efixed-spe_data.en)/2.07); % line-vector (1,ne)
49   Qx=ki*ones(size(spe_data.det_theta,1),size(spe_data.en,2))...
50      -cos(spe_data.det_theta)*kf; % matrix (ndet,ne)
51   if ~isfield(spe_data,'det_psi'),
52      data.det_psi=zeros(size(spe_data.det_theta));
53      disp(['Assume psi=0 for all detectors']);
54   end
55   Qy=-(sin(spe_data.det_theta).*cos(spe_data.det_psi))*kf;
56        Qz=-(sin(spe_data.det_theta).*sin(spe_data.det_psi))*kf;
57        Q=cat(3,Qx,Qy,Qz);
58   
59elseif spe_data.emode==2,
60   
61   % ========================================================================
62   % For indirect-geometry spectrometers like IRIS
63        % efixed = monochromatic scattered energy (meV) for a white incident
64beam 
65   % here all detectors are in the horizontal plane with Psi=0
66   % scattering geometry diagram in notebook computing 2, page 2-14
67   % ========================================================================
68   
69   ki=sqrt((spe_data.efixed+spe_data.en)/2.07); % line-vector (1,ne)
70   kf=sqrt(spe_data.efixed/2.07);       % scalar
71        Qx=ones(size(spe_data.det_theta))*ki-
72kf*cos(spe_data.det_theta)*ones(size(spe_data.en)); % matrix (ndet,ne)
73        Qy=-kf*(sin(spe_data.det_theta))*ones(size(spe_data.en));       %
74(ndet,1)*(1,ne)
75        Qz=zeros(size(Qx));
76        Q=cat(3,Qx,Qy,Qz);
77
78else
79   disp('Only inelastic direct-geometry (emode=1, HET, MARI)');
80   disp(' or inelastic indirect-geometry (emode=2, IRIS) spectrometer modes
81available.');
82        disp(['emode=' num2str(emode) ' not implemented. Transformation not
83performed']);
84   Q=[];
85   return
86end
87
88